package com.rqbl.controller;

import com.rqbl.entity.User;
import com.rqbl.myutils.PageBean;
import com.rqbl.myutils.TableJson;
import com.rqbl.service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bruce
 * @since 2024-07-19
 */
@Controller
@RequestMapping("/friend")
public class FriendController {

    @Autowired
    private FriendService friendService;

    @RequestMapping("/getFriendByUid")
    @ResponseBody
    public TableJson getFriendByUid(HttpSession session,Integer page,Integer limit){
        PageBean pageBean = new PageBean();
        pageBean.setPage(page);
        pageBean.setPageSize(limit);
        User user = (User) session.getAttribute("user");
        friendService.getFriendByUid(pageBean,user);
        TableJson tableJson = new TableJson();
        tableJson.setCode(0);
        tableJson.setMsg("success");
        tableJson.setData(friendService.getFriendByUid(pageBean,user));
        tableJson.setCount(pageBean.getTotalSize());
        return tableJson;
    }

    @RequestMapping("deleteFriendByUid")
    @ResponseBody
    public String  deleteFriendByUid(HttpSession session,Integer uid){
        User user = (User) session.getAttribute("user");
        friendService.deleteFriendByUid(user.getUid(),uid);
        return "success";
    }
}
